package com.scrawler.mysql.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.scrawler.util.MysqlConfig;
import com.scrawler.vo.NewsContent;

public class ForumDao {

	public static void insert(List<NewsContent> contents){
		if(contents==null || contents.size()<1)return;
		 Connection conn = MysqlConfig.getConnection();
		 String sql = "insert into news_content(recdId,title,author,content,recddate,url,vector,origin,hits,comments,reprints,webname,pdmc,rkdz,industry)" +
		 		" value(?,?,?,?,?,?,?,?,?) ";
		 PreparedStatement ps = null;
		try {
			ps = conn.prepareStatement(sql);
			for(NewsContent content: contents){
				ps.setInt(1, content.getType_id());
				ps.setString(2, content.getTitle());
				String author = content.getAuthor();
				if(author!=null && author.length()>255){
					author.substring(254);
				}
				ps.setString(3, author);
				ps.setString(4, content.getContent());
				ps.setString(5, content.getPub_time());
				ps.setString(6, content.getUrl());
				String hits = content.getHits();
				if(hits!=null && hits.length()>255){
					hits = hits.substring(254);
				}
				ps.setString(7, hits);
				ps.setString(8, content.getComments());
				ps.setString(9, content.getReprints());
				ps.addBatch();
			}
			ps.executeBatch();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}
		finally{
			MysqlConfig.close(conn, ps);
		}
	 }
	
	
}
